import { writeFile, writeFileSync } from 'fs';

import { mkdirSafetySync } from './path.utils';

function writeFileTo(path: string, fileContent: string | Buffer) {
    return new Promise((reslove, reject) => {
        mkdirSafetySync(path);

        writeFileSync(path, fileContent, { encoding: 'utf8' });

        writeFile(path, fileContent, (err) => {
            if (err) {
                reject(err);
            }

            reslove(`write file success.\nPath is ${path}`);
        });
    });
}

export { writeFileTo };
